package com.xtayfjpk.dwr.test;

import java.io.File;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.webapp.WebAppContext;


public class Launcher {

	public static void main(String[] args) throws Exception {
		String userDir = System.getProperty("user.dir");
		File webapp = new File(userDir, "src/main/webapp");
		System.out.println(webapp);
		String contextPath = userDir.substring(userDir.lastIndexOf(File.separator) + 1);
		System.out.println(contextPath);
		
		Server server = new Server();
		
		
		SslContextFactory sslContextFactory = new SslContextFactory();
		sslContextFactory.setNeedClientAuth(false);
		sslContextFactory.setKeyStorePath("H:/certtest/server.jks");
		sslContextFactory.setKeyStorePassword("123456");
		sslContextFactory.setKeyManagerPassword("123456");
		sslContextFactory.setCertAlias("localhost");
		SslSocketConnector sslSocketConnector = new SslSocketConnector(sslContextFactory);
		sslSocketConnector.setPort(443);
		
		server.addConnector(sslSocketConnector);
		
		WebAppContext webAppContext = new WebAppContext(webapp.getAbsolutePath(), "/" + contextPath);

		HandlerCollection handlers = new HandlerCollection();
		handlers.addHandler(webAppContext);
		server.setHandler(handlers);

		server.start();
		

	}

}
